package com.heboan.hadoop.mr_homework;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class MyReducer extends Reducer<MyBean, NullWritable, IntWritable, MyBean> {

    int sortNum = 0;
    IntWritable k = new IntWritable();
    @Override
    protected void reduce(MyBean key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        for (NullWritable value : values) {

            // map已经经过了排序，排序顺序+1即可，作为k,数据作为v
            sortNum += 1;
            k.set(sortNum);

            context.write(k, key);
        }
    }
}
